package com.main.tripplanner.dao;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.main.tripplanner.persistent.PersistentEntity;

@Transactional
abstract public class AbstractDAO {

	@Autowired
	protected SessionFactory sessionFactory;
	
	public void saveEntity(PersistentEntity entity){
//		Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(entity);
		this.sessionFactory.getCurrentSession().save(entity);
		sessionFactory.getCurrentSession().flush();
		sessionFactory.getCurrentSession().evict(entity);
	}
	
	public void updateEntity(PersistentEntity entity){
		this.sessionFactory.getCurrentSession().update(entity);
		sessionFactory.getCurrentSession().flush();
		sessionFactory.getCurrentSession().evict(entity);
	}
	
	public void deleteEntity(PersistentEntity entity){
		this.sessionFactory.getCurrentSession().delete(entity);
	}

}
